<?php

/**
 * @Author: Eden
 * @Date:   2019-07-10 18:26:09
 * @Last Modified by:   Eden
 * @Last Modified time: 2019-07-10 23:24:35
 */
namespace App\Transformers;

use App\Models\Ip;
use League\Fractal\TransformerAbstract;

class IpTransformer extends TransformerAbstract
{

	protected $availableIncludes = ['informations'];

	public function transform(Ip $ip)
	{
		return [
			'id' => $ip->id,
			'ip_address' => $ip->ip_address,
			'info' => $ip->info,
			'created_at' => $ip->created_at->toDateTimeString(),
			'updated_at' => $ip->updated_at->toDateTimeString(),
		];
	}

	public function includeInformations(Ip $ip)
	{
		if($ip->informations){
			return $this->collection($ip->informations, new InformationTransformer());
		}
	}

}
